package erciyuan.hoolai.com.jwtdemo2;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Toast;

import org.json.JSONException;
import org.json.JSONObject;

import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

public class MainActivity extends AppCompatActivity {
    JSONObject payload;
    JSONObject header;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        try {
            header= new JSONObject();
            header.put("typ", "JWT");
            header.put("alg",  "HS256");

            payload= new JSONObject();
            payload.put("name", "jack");
            payload.put("age", 12);

        } catch (JSONException e) {
            e.printStackTrace();
        }


        setContentView(R.layout.activity_main);
        findViewById(R.id.activity_main).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                try {
                 String str=   DBWebSignature.gettoken(header,payload);
                 Log.e("token",str);


                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });


    }
}
